var showCharts;
require(['highcharts'], function () {
	
	showCharts = function(lineId, organId, rcrdTime, fuelTypeCode, rowDatas, beginTime, endTime){
		$("#manySpeedAnalysisChartDiv").empty();
		$("#manySpeedAnalysisChartDiv").append("<div style='clear:left;'></div>"
		+"<div id='manyLineAnalysisChart' style='width: 500px;height: 300px; float: left;border:1px solid #2f92e6;'></div>"
		+"");
		
		for(var i=0;i < rowDatas.length; i++){
			var title="";
			if(rowDatas[i].drvName==""){
				title = rowDatas[i].licPltNo +"转速分析";
			}else{
				title = rowDatas[i].drvName +"转速分析";
			}
			if(i % 2==0){
				if(i==0){
					$("#manySpeedAnalysisChartDiv").append("<div id='speedAnalysisChart"+i+"' style='width: 500px;height: 300px; float: left;border:1px solid #2f92e6;margin-left:5px;'></div>");
				}else{
					$("#manySpeedAnalysisChartDiv").append("<div id='speedAnalysisChart"+i+"' style='width: 500px;height: 300px; float: left;border:1px solid #2f92e6;margin-left:5px;margin-top:5px;'></div>");
				}
			}else{
				$("#manySpeedAnalysisChartDiv").append("<div style='clear:left;'></div><div id='speedAnalysisChart"+i+"' style='width: 500px;height: 300px; float: left;clear: left;;border:1px solid #2f92e6;margin-top:5px;'></div>");
			}
			$("#speedAnalysisChart"+i+"" ).highcharts({
				chart: {
					plotBackgroundColor: null,
					plotBorderWidth: null,
					plotShadow: false
				},
				colors:['#4D526D','#A78B5A','#FEE303','#B7E138','#F29B42','#ED4747','#50E138','#1B9784'],
				title: {
					text: ""+title+""
				},
				credits: {
					enabled: false
				},
				plotOptions: {
					pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						// innerSize: '0%',
						dataLabels: {
							enabled: false
						},
						distance: -30,
						showInLegend: true
					}
				},
				tooltip: {
					pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
				},
				legend: {
					borderWidth: 0
				},
				series: [
					{
						type: 'pie',
						name: '转速分析',
						data: [
							['怠速时长', parseFloat(rowDatas[i].idliDuraRate.substring(0,rowDatas[i].idliDuraRate.indexOf('%')))||0],
							['空调怠速时长', parseFloat(rowDatas[i].airCondiIdliDuraRate.substring(0,rowDatas[i].airCondiIdliDuraRate.indexOf('%')))||0],
							['低转时长', parseFloat(rowDatas[i].slowSpdRevoDuraRate.substring(0,rowDatas[i].slowSpdRevoDuraRate.indexOf('%')))||0],
							['绿区时长',parseFloat(rowDatas[i].lowEnerAreaDriveDuraRate.substring(0,rowDatas[i].lowEnerAreaDriveDuraRate.indexOf('%')))||0],
							['高转时长', parseFloat(rowDatas[i].highSpdRevoDuraRate.substring(0,rowDatas[i].highSpdRevoDuraRate.indexOf('%')))||0],
							['超转时长',parseFloat(rowDatas[i].suspeedDuraRate.substring(0,rowDatas[i].suspeedDuraRate.indexOf('%')))||0],
							['最经济转速时长', parseFloat(rowDatas[i].mostEcnRtteSpdDuraRate.substring(0,rowDatas[i].mostEcnRtteSpdDuraRate.indexOf('%')))||0],
							['反转时长', parseFloat(rowDatas[i].revDuraRate.substring(0,rowDatas[i].revDuraRate.indexOf('%')))||0]
						]
					}
				]
			});
			
		}
		
		$("#manySpeedAnalysisChartDiv").append("<div style='clear:both;'></div>");
		
		//线路平均
		var params = [];
		params.push({
			name : "beginTime",
			value : beginTime
		},{
			name : "endTime",
			value : endTime
		},{
			name : "lineId",
			value : lineId
		},{
			name : "organId",
			value : organId
		},{
			name : "fuelTypeCode",
			value : fuelTypeCode
		});
		$.ajaxExt({
			url : "/speedAnalysis/searchLineEnergyChart.htm",
			data : params
		}).done(function(result){
			$("#manyLineAnalysisChart").highcharts({
				chart: {
					plotBackgroundColor: null,
					plotBorderWidth: null,
					plotShadow: false
				},
				colors:['#4D526D','#A78B5A','#FEE303','#B7E138','#F29B42','#ED4747','#50E138','#1B9784'],
				title: {
					text: '线路平均转速分析'
				},
				credits: {
					enabled: false
				},
				plotOptions: {
					pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						// innerSize: '0%',
						dataLabels: {
							enabled: false,
							inside: true,
							format: '<b>{point.name}</b>: {point.percentage:.2f}%',
							style: {
								color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
							}
						},
						distance: -30,
						showInLegend: true
					}
				},
				tooltip: {
					pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
				},
				legend: {
					borderWidth: 0
				},
				series: [
					{
						type: 'pie',
						name: '转速分析',
						data: [
							['怠速时长', parseFloat(result[0].idliDuraRate.substring(0,result[0].idliDuraRate.indexOf('%')))||0,'#ff0000'],
							['空调怠速时长', parseFloat(result[0].airCondiIdliDuraRate.substring(0,result[0].airCondiIdliDuraRate.indexOf('%')))||0],
							['低转时长', parseFloat(result[0].slowSpdRevoDuraRate.substring(0,result[0].slowSpdRevoDuraRate.indexOf('%')))||0],
							['绿区时长',parseFloat(result[0].lowEnerAreaDriveDuraRate.substring(0,result[0].lowEnerAreaDriveDuraRate.indexOf('%')))||0],
							['高转时长', parseFloat(result[0].highSpdRevoDuraRate.substring(0,result[0].highSpdRevoDuraRate.indexOf('%')))||0],
							['超转时长',parseFloat(result[0].suspeedDuraRate.substring(0,result[0].suspeedDuraRate.indexOf('%')))||0],
							['最经济转速时长', parseFloat(result[0].mostEcnRtteSpdDuraRate.substring(0,result[0].mostEcnRtteSpdDuraRate.indexOf('%')))||0],
							['反转时长', parseFloat(result[0].revDuraRate.substring(0,result[0].revDuraRate.indexOf('%')))||0]
						]
					}
				]
			});
		});
	};
	
	
	
});